// winhttp_async.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "AsyncWinHttp.h"
#include <string>

HANDLE hEvent = NULL;

void WinHttp_CallBack(AsyncWinHttp* asyncWinHttp)
{
	if (asyncWinHttp->status.Status() == ASYNC_WINHTTP_ERROR)
	{
		printf("%S", asyncWinHttp->status.Desc().c_str());
	}
	else
	{
		//std::string response;
		//asyncWinHttp->GetResponseRaw(response);
		//printf("%s", response.c_str());
	}
	SetEvent(hEvent);
}

int _tmain(int argc, _TCHAR* argv[])
{
	hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    
    char sOutPutFn[MAX_PATH];
    strcpy(sOutPutFn, "tt.mp3");

	AsyncWinHttp http;
	http.Initialize(WinHttp_CallBack);
    http.SetTimeout(9 * 1000);
    http.SetOutFileName(sOutPutFn);
    http.SendRequest(L"http://dict.cn/mp3.php?q=Shfz7");
     	
	WaitForSingleObject(hEvent, INFINITE);

	CloseHandle(hEvent);

    DWORD len = http.GetResponseLen();
    
	//fgetc(stdin);
	return 0;
}

